<?php

namespace app\admin\model;

use think\Model;

class Member extends Model
{
    // 表名
    protected $name = 'member';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'gender_text',
        'authen_status_text',
        'rec_status_text',
        'rec_start_time_text',
        'rec_end_time_text',
        'last_login_time_text',
        'create_time_text'
    ];
    

    
    public function getGenderList()
    {
        return ['0' => __('Gender 0'),'1' => __('Gender 1')];
    }     

    public function getAuthenStatusList()
    {
        return ['0' => __('Authen_status 0'),'1' => __('Authen_status 1')];
    }     

    public function getRecStatusList()
    {
        return ['0' => __('Rec_status 0'),'1' => __('Rec_status 1')];
    }     


    public function getGenderTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
        $list = $this->getGenderList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAuthenStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['authen_status']) ? $data['authen_status'] : '');
        $list = $this->getAuthenStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRecStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['rec_status']) ? $data['rec_status'] : '');
        $list = $this->getRecStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRecStartTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['rec_start_time']) ? $data['rec_start_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getRecEndTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['rec_end_time']) ? $data['rec_end_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getLastLoginTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['last_login_time']) ? $data['last_login_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setRecStartTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setRecEndTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setLastLoginTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


    public function car()
    {
        return $this->belongsTo('Car', 'car_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function house()
    {
        return $this->belongsTo('House', 'house_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function income()
    {
        return $this->belongsTo('Income', 'income_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function education()
    {
        return $this->belongsTo('Education', 'education_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function marriage()
    {
        return $this->belongsTo('Marriage', 'marriage_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function zodiac()
    {
        return $this->belongsTo('Zodiac', 'zodiac_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function tags()
    {
        return $this->belongsTo('Tags', 'tags_ids', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
